<template>
  <div>
    <div style="width: 430px; float: right">
      <el-input @keyup.enter.native="searchEnterFun($event)" placeholder="请输入公式名称" v-model="name">
        <i class="el-input__icon el-icon-search" slot="prefix"></i>
        <el-button :icon="appendIcon" slot="append" v-on:click="switchAppend"></el-button>
      </el-input>
    </div>
    <div id="advance" style="padding: 10px; float: right" v-if="showAdvance">
      <div>
        <div :item="item" :key="item.name" v-for="item in items">
          <div style="display: inline-block;text-align: right;width: 90px;margin-top: 10px"><span>{{item.name}}</span>
          </div>
          <div style="display: inline-block">
            <el-cascader
              :options="item.tagId"
              :props="cascadeProps"
              :show-all-levels="false"
              @change="handleChange"
              clearable
              placeholder="请选择"
              size="small"
              style="width: 300px"
              v-model="item.subject"
            ></el-cascader>
          </div>
        </div>
        <div style="display: inline-block;text-align: right;width: 90px">公式类型</div>
        <div style="display: inline-block;margin-top: 10px">
          <el-select clearable placeholder="公式类型" size="small" style="width: 300px" v-model="type">
            <el-option
              :key="item.value"
              :label="item.label"
              :value="item.value"
              v-for="item in types">
            </el-option>
          </el-select>
        </div>
      </div>
      <div style="margin-top: 60px; right: 10px;">
        <el-row>
          <el-col :offset="7" :span="9">
            <div style="margin-left: 90px;height: 32px; width: 88px;">
              <el-button size="small" v-on:click="advanceCancel">取 消</el-button>
            </div>
          </el-col>
          <el-col :offset="0.8" :span="2">
            <div div style="margin-left: 5px;height: 32px; width: 88px;">
              <el-button size="small" type="success" v-on:click="reset">重 置</el-button>
            </div>
          </el-col>
          <el-col :offset="2" :span="2">
            <div div style="margin-left: 5px;height: 32px; width: 88px;">
              <el-button size="small" type="success" v-on:click="advanceConfirm">确 定</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props: ['value', 'tableInnerData'],
    name: "MedicalCalculatorSearch",
    data() {
      return {
        tableData: [],
        uploadVisible: false,
        componentName: "",
        show: "true",
        noData: false,
        showAdvance: false,
        appendIcon: "el-icon-caret-bottom",
        name: '',
        subject: '',
        searchData: [],
        department: '学科',
        subjectOptions: [],
        cascadeProps: {multiple: true},
        standardTerminology: "",
        currentPage: 0,
        pageSize: 10,
        totalNum: 0,
        types: [{
          value: 1,
          label: '计算型'
        }, {
          value: 2,
          label: '评分型'
        }, {
          value: 3,
          label: '描述型'
        }],
        type: '',
        items: []
      };
    },
    methods: {
      switchAppend: function () {
        if (this.showAdvance) {
          this.showAdvance = false;
          this.appendIcon = "el-icon-caret-bottom";
        } else {
          this.showAdvance = true;
          this.appendIcon = "el-icon-caret-top";
        }
        this.showSubject()
      },
      reset() {
        for (let i = 0; i < this.items.length; i++) {
          if (this.items[i].subject) {
            this.items[i].subject = ''
          }
        }
        this.subject = ''
        this.name = ''
        this.type = ''
      },
      searchTerminology: function () {
      },
      advanceCancel: function () {
        this.showAdvance = false;
      },
      advanceConfirm: function () {
        this.Confirm()
      },
      searchEnterFun(e) {
        const keyCode = window.event ? e.keyCode : e.which;
        if (keyCode === 13) {
          this.Confirm()
        }
      },
      handleChange(value) {
        this.subject = value;
      },
      Confirm: function () {
        this.axios.get('/pmph/action/medicalCalculator/selectMedicalCalculatorList', {
          params: {
            currentPage: 0,
            pageNum: 10,
            name: this.name,
            subject: JSON.stringify(this.subject),
            type: this.type,
            status: this.value
          }
        }).then((response) => {
          this.noData = response.data.totalNum <= 0;
          this.searchData = response.data.tableData
          this.totalNum = response.data.totalNum;
          this.$emit('Confirm', this.searchData, this.totalNum, this.name, this.subject, this.type)
          this.showAdvance = false;
        }).catch((error) => {
          console.error(error);
          this.tableData = [];
          this.noData = true;
          this.$message.error("未能请求到数据");
        })
      },
      showSubject: function () {
        // 获取分类数据
        this.axios.get("/pmph/action/medicalCalculator/selectTagData", {
          params: {
            tags: 'department'
          }
        })
          .then((response) => {
            this.subjectOptions = response.data
          })
          .catch((error) => {
            this.$message.error("获取分类数据失败")
          })
      }
    }, created() {
      this.axios.get("/pmph/action/medicalCalculator/selectSubject", {
        params: {}
      })
        .then((response) => {
          this.items = response.data.fields
        })
    }
  };
</script>

<style scoped>

</style>
